﻿using SQLDeploy.Data.Connections;
using SQLDeploy.Data.Files;
using SQLDeploy.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SQLDeploy.Builder.Controls.Environments
{
    /// <summary>
    /// Interaction logic for AddDialog.xaml
    /// </summary>
    public partial class AddDialog : Window
    {
        internal static SQLDeploy.Data.Files.Connections _Connections;

        public AddDialog(SQLDeploy.Data.Files.Connections connections, Data.Environments.Environment environmentToClone)
        {
            Check.notNull(connections, "connections");
            _Connections = connections;
            init(environmentToClone);
        }

        public AddDialog(SQLDeploy.Data.Files.Connections connections)
        {
            Check.notNull(connections, "connections");
            _Connections = connections;
            init(null);
        }

        private void init(Data.Environments.Environment environmentToClone)
        {
            InitializeComponent();
            Data.Environments.Environment env = new Data.Environments.Environment();
            if (environmentToClone != null)
            {
                
                foreach (_BaseConnection con in environmentToClone.Connections)
                {
                    env.Connections.Add(con);
                }
            }
            DataContext = env;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }
                
    }
}
